
#ifndef __FILESTREAM_H__
#define __FILESTREAM_H__

#include <fstream>
#include <vector>
#include <string>
#include "TEDefs.h"
using namespace std;

class FileStream
{
public:

	// Constructor
	FileStream(bool _read);

	// Open / Close
	void Open(const string &fileName, bool _binary, const string &_delim = " ");
	void Close();

	// Is Open
	bool IsOpen();

	// Is Still Good
	bool IsGood();

	// In Binary
	bool IsBinary() const { return binary; }

	// For binary
	void Read(char *ptr, ulong size);
	void Write(char *ptr, ulong size);

	// Read / Write a flag (binary)
	void WriteFlag(bool flag);
	bool ReadFlag();

	// For text, returns "" if error
	string GetString();

	// File Streams
	ofstream oFile;
	ifstream iFile;

private:

	// Tokens
	vector<string> tokens;
	uchar tokI;

	// Delimiters
	string delim;

	// Read / Write
	bool read;

	// Binary / Text
	bool binary;
};

#endif // __FILESTREAM_H__